#include <iostream>
#define N 100

using namespace std;

void intersection(int array_a[], int array_b[], int elements_a, int elements_b){
int i=0;
int j=0;
while(i < elements_a && j < elements_b){
    if(array_a[i] < array_b[j])
      i++;
    else if(array_b[j] < array_a[i])
      j++;
    else {
      cout<<array_b[j++]<<" ";
      i++;}
  }
}


void readintVector_A(int array_a[], int elements_a){
for (int i=0; i<elements_a; i++){
	cout<<"a["<<i<<"]=";
	cin>>array_a[i];
	cout<<"\n";}
}

void readintVector_B(int array_b[], int elements_b){
for (int i=0; i<elements_b; i++){
	cout<<"a["<<i<<"]=";
	cin>>array_b[i];
	cout<<"\n";}
}


int main(){
int array_a[N];
int array_b[N];

int elements_a;
int elements_b;

cout<<"Type the number of elements you want in the array A: ";
cin>>elements_a;
readintVector_A(array_a, elements_a);

cout<<"Type the number of elements you want in array B: ";
cin>> elements_b;
readintVector_B(array_b, elements_b);

cout<<"The original array A is ";
for(int i=0; i<elements_a; i++){
	cout<<array_a[i]<<" ";}
cout<<endl;

cout<<"The original array B is ";
for(int i=0; i<elements_b; i++){
	cout<<array_b[i]<<" ";}
cout<<endl;

cout<<"The intersection between A and B is: "<<endl;
intersection( array_a, array_b,  elements_a,  elements_b);


return 0;
}
